package com.xxxx.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * RabbitMQ配置类-Fanout模式
 */
@Configuration
public class RabbitMQFanoutConfig {

    private static final String QUEUE01 = "queue_fanout01";
    private static final String QUEUE02 = "queue_fanout02";
    private static final String EXCHANGE = "fanoutExchange";

    @Bean
    public Queue fanoutQueue01() {
        return new Queue(QUEUE01);
    }

    @Bean
    public Queue fanoutQueue02() {
        return new Queue(QUEUE02);
    }

    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(EXCHANGE);
    }

    @Bean
    public Binding bindingFanout01() {
        return BindingBuilder
                .bind(fanoutQueue01())
                .to(fanoutExchange());
    }

    @Bean
    public Binding bindingFanout02() {
        return BindingBuilder
                .bind(fanoutQueue02())
                .to(fanoutExchange());
    }
}
